import copy

n, m = map(int, input().split())


class UnionFind:
    def __init__(self, x):
        self.fa = list(range(x + 1))

    def find(self, x):
        if self.fa[x] != x:
            self.fa[x] = self.find(self.fa[x])
        return self.fa[x]

    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return False
        self.fa[root_y] = root_x
        return True


stack = []
uf = UnionFind(n)
for _ in range(m):
    t = input()
    if len(t) == 1:
        if stack:
            uf = stack.pop()
    else:
        s, x, y = map(int, t.split())
        if s == 1:
            stack.append(copy.deepcopy(uf))
            uf.union(x, y)
        elif s == 3:
            root_x = uf.find(x)
            root_y = uf.find(y)
            if root_x == root_y:
                print("Yes")
            else:
                print("No")
